import esbuild from 'esbuild';

import {dirname, resolve} from 'node:path';

import {fileURLToPath} from 'node:url';

import {createRequire} from 'node:module';

import minimist from 'minimist';

const argv = minimist(process.argv.slice(2));

const target = argv._?.[0] || 'reactivity';

const format = argv.f || 'esm';

const require = createRequire(import.meta.url);
const __dirname = dirname(fileURLToPath(import.meta.url));

const pkg = require(`./../packages/${target}/package.json`)

esbuild.context({
    entryPoints: [resolve(__dirname, `./../packages/${target}/src/index.ts`)],
    outfile: resolve(__dirname, `./../packages/${target}/dist/index.js`),
    bundle: true,
    sourcemap: true,
    format,
    globalName: pkg?.buildOptions?.nmae,
    platform: format === 'ejs' ? 'node' : 'browser',

}).then(ctx => ctx.watch());